package com.n9;

import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author ice
 * @since 2019/1/15 9:34
 */
public class T {
    public static void main(String[] args) throws IOException {
        InputStream in = T.class.getResourceAsStream("/求购群消息记录.txt");
        List<String> lines = IOUtils.readLines(new InputStreamReader(in, "UTF-8"));

        Set<String> qqNos = new HashSet<>();
        List<StringBuilder> sbs = new ArrayList<>();
        StringBuilder sb = new StringBuilder();
        Pattern compile = Pattern.compile("(\\d{4}-\\d{1,2}-\\d{1,2} \\d{1,2}:\\d{1,2}:\\d{1,2}.*(\\d*))|(\\(\\d*\\) \\d{1,2}:\\d{1,2}:\\d{1,2})");
        for (String line : lines) {
            Matcher matcher = compile.matcher(line);
            if (matcher.find()) {
//                int begin = line.indexOf("(") - 1;
//                int end = line.indexOf(")");
//                qqNos.add(line.substring(begin, end));

                if (sb.length() > 0) {
                    sbs.add(sb);
                    sb = new StringBuilder();
                }
                continue;
            }

            sb.append(line);
        }

        Set<String> msgs = new HashSet<>();
        sbs.forEach(s -> {
            String msg = s.toString();
            if (msg.indexOf("购") >= 0
                    || msg.indexOf("求") >= 0
                    || msg.indexOf("急") >= 0
                    || msg.indexOf("私") >= 0
                    || msg.indexOf("收") >= 0
                    || msg.indexOf("联系") >= 0
                    || msg.indexOf("有没有") >= 0
                    || msg.indexOf("谁有") >= 0
                    || msg.indexOf("状态不限") >= 0
                    || msg.indexOf("需要") >= 0
                    || msg.indexOf("发明未缴费") >= 0
                    ) {
                msgs.add(s.toString());
            } else {
                System.out.println(msg);
            }
        });
        System.out.println(sbs.size() + "\t" + msgs.size() + "\tqqNos:" + qqNos.size());

    }
}
